package com.cloud.code.算法.排序.归并排序.冒泡排序;

import com.alibaba.fastjson.JSON;
import org.junit.Test;

public class Demo1 {

    @Test
    public void test2() {
//        printPrime(20);
        prient(20);
    }

    @Test
    public void test() {
        int[] arr = new int[]{34, 2, 5, 9, 23, 21, 25, 32};
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }

        System.out.println(JSON.toJSON(arr));
    }


    /**
     * 打印n以内的素数
     *
     * @param n
     */
    public void printPrime(int n) {
        //是否为质数
        boolean isPrime;
        for (int i = 1; i <= n; i++) {
            isPrime = true;
            for (int j = 2; j < i; j++) {
                //若能除尽，则不为质数
                if ((i % j) == 0) {
                    isPrime = false;
                    break;
                }
            }
            //如果是质数，则打印
            if (isPrime) {
                System.out.println(i);
            }
        }
    }

    public void prient(int temp) {

        for (int i = 1; i <= temp; i++) {
            boolean isprime = true;
            for (int j = 2; j < i; j++) {
                if (i % j == 0) {
                    isprime = false;
                    break;
                }
            }
            if (isprime) {
                System.out.println(i);
            }
        }
    }


}
